package com.andy.qhb.action;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import com.andy.qhb.game.GameUtils;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.game.Global;
import com.andy.qhb.game.QhbGame;
import com.andy.qhb.game.Room;
import com.andy.qhb.utils.GmAction;
import com.andy.qhb.utils.SendUtil;
import com.andy.qhb.websocket.MySocketSession;

/**
 * 发包
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_121)
public class Action121 implements IWebAction{

	@Override
	public void doAction(MySocketSession myWebSocket, Map<String, Object> data) {
		
		GameUser user = myWebSocket.getUser();
		Room room = user.getRoom();
		if(room == null)return;
		Integer coin = MapUtils.getInteger(data, "coin");
		Integer num = MapUtils.getInteger(data, "num");
		Integer lei = MapUtils.getInteger(data, "lei");
		
		QhbGame game = new QhbGame(coin,num,lei);
		game.setCreater(user);
		Global.addGame(game);
		GameUtils.saveDb(game.toEntity());
		
		SendUtil.send121(room,game);
		
	}

	
	
	
}
